var a = require("../../@babel/runtime/helpers/defineProperty"), t = require("../../@babel/runtime/helpers/typeof"), e = getApp(), i = "0";

Page({
    data: {
        team_agent: "",
        language: "",
        mailLanguage: "",
        mailTeamDividendTitle: "",
        mailDividend: "",
        level_name: "",
        dividend_ratio: "",
        next_dividend_ratio: "",
        ratioDatas: [],
        activeName: 0,
        first_content: [],
        second_content: [],
        third_content: [],
        four_content: [],
        bonus_active: !0,
        leveling_active: !0,
        prize_active: !0,
        extra_active: !0,
        record_index: "",
        record_key: "",
        tab_name: "提成",
        bonus_lable: "",
        leveling_label: "",
        prize_label: "",
        bonus_save: [],
        leveling_save: [],
        prize_save: [],
        peopleCount: 0,
        teamPerformance: {},
        showRed: 0,
        dividend_amount: "",
        dividend: {},
        flat_prize: {},
        award_gratitude: {},
        extra_award: {},
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        dividend_type: "0",
        is_activation_code: "0",
        display1: -1,
        teamDividendLang: {},
        extra_award_label: ""
    },
    onLoad: function(a) {
        this.checkrouter(), this.initMailLanguage(), this.getData(0), this.getDividendList("0"), 
        this.initPageData();
    },
    checkrouter: function() {
        var a = this;
        try {
            var e = function() {
                var t = wx.getStorageSync("yz_basic_info");
                t.lang.team_dividend && a.setData({
                    teamDividendLang: t.lang.team_dividend
                });
                for (var e = t.popularize_page.mini.vue_route, i = [ "pages/index/index", "pages/category_v2/category_v2", "pages/member/extension/extension", "pages/buy/cart_v2/cart_v2", "pages/member/index_v2/index_v2" ], n = 0; n < e.length; n++) if ("teamAgentCenter" == e[n]) {
                    console.log(t.popularize_page.mini.mini_url + "跳转的路径");
                    for (var d = t.popularize_page.mini.mini_url.substr(1), s = 0; s < i.length; s++) i[s] == d ? wx.reLaunch({
                        url: "/" + d
                    }) : wx.showToast({
                        title: "未开启推广权限",
                        duration: 1e3,
                        icon: "none",
                        success: function() {
                            setTimeout(function() {
                                wx.redirectTo({
                                    url: t.popularize_page.mini.mini_url
                                });
                            }, 1e3);
                        }
                    });
                    return {
                        v: void 0
                    };
                }
            }();
            if ("object" === t(e)) return e.v;
        } catch (a) {
            console.log(a);
        }
    },
    onReady: function() {
        var a = wx.getStorageSync("langIndex");
        this.setData({
            language: a.en
        });
    },
    onShow: function() {
        var a = this;
        wx.getStorage({
            key: "yz_basic_info",
            success: function(t) {
                console.log(t), setTimeout(function() {
                    a.setData({
                        team_agent: t.data.lang.team_dividend && t.data.lang.team_dividend.my_agent ? t.data.lang.team_dividend.my_agent : "我的客户"
                    });
                }, 2e3);
            }
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreDividendList() : wx.showToast({
            title: "没有更多数据",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    initMailLanguage: function() {
        var a, t = this, i = e.getNetAddresss("setting.get-lang-setting");
        e._getNetWork({
            url: i,
            success: function(i) {
                var n = i.data;
                if (1 === n.result) {
                    a = n.data;
                    var d = e.setMailLanguage("提成", a.team_dividend.dividend), s = e.setMailLanguage("经销商管理中心", a.team_dividend.team_agent_centre), r = e.setMailLanguage("佣金", a.team_dividend.dividend_amount), o = e.setMailLanguage("提成", a.team_dividend.dividend), _ = e.setMailLanguage("额外奖励", a.team_fjyx.extra_award);
                    t.setData({
                        mailLanguage: a,
                        mailDividend: d,
                        mailTeamDividendTitle: s,
                        dividend_amount: r,
                        tab_name: o,
                        extra_award_label: _
                    }), console.log(t.data.mailLanguage, "语言"), wx.setNavigationBarTitle({
                        title: s || ""
                    }), t.initInfo();
                } else wx.showToast({
                    title: n.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getTeamDividend: function() {
        var a = this, t = e.getNetAddresss("plugin.team-fjyx.api.team-dividend.getTeamDividend");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 === e.result ? a.setData({
                    dividend: e.data.dividend,
                    flat_prize: e.data.flat_prize,
                    award_gratitude: e.data.award_gratitude,
                    extra_award: e.data.extra_award
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getPeople: function(a) {
        this.setData({
            peopleCount: a
        });
    },
    getShowRed: function(a) {
        this.setData({
            showRed: a
        });
    },
    getTeamPerformance: function(a) {
        this.setData({
            teamPerformance: a
        });
    },
    isGratitude: function(a) {
        var t = e.setMailLanguage("提成", this.data.mailLanguage.team_dividend.dividend), i = e.setMailLanguage("平级奖", this.data.mailLanguage.team_fjyx.flat_prize), n = e.setMailLanguage("感恩奖", this.data.mailLanguage.team_dividend.award_gratitude);
        this.setData({
            bonus_lable: t,
            leveling_label: i,
            prize_label: n,
            extra_label: "额外分红",
            record_index: a.is_flat_prize || null,
            record_key: a.is_award_gratitude || null
        }), 1 == a.is_flat_prize && 1 == a.is_award_gratitude && 1 == a.is_extra_award ? this.setData({
            leveling_active: !0,
            prize_active: !0,
            extra_active: !0
        }) : 1 == a.is_flat_prize && 1 == a.is_award_gratitude && 0 == a.is_extra_award ? this.setData({
            leveling_active: !0,
            prize_active: !0,
            extra_active: !1
        }) : 0 == a.is_flat_prize && 1 == a.is_award_gratitude && 1 == a.is_extra_award ? this.setData({
            leveling_active: !1,
            prize_active: !0,
            extra_active: !0
        }) : 0 == a.is_flat_prize && 1 == a.is_award_gratitude && 0 == a.is_extra_award ? this.setData({
            leveling_active: !1,
            prize_active: !0,
            extra_active: !1
        }) : 1 == a.is_flat_prize && 0 == a.is_award_gratitude && 0 == a.is_extra_award ? this.setData({
            leveling_active: !0,
            prize_active: !1,
            extra_active: !1
        }) : 1 == a.is_flat_prize && 0 == a.is_award_gratitude && 1 == a.is_extra_award ? this.setData({
            leveling_active: !0,
            prize_active: !1,
            extra_active: !0
        }) : 0 == a.is_flat_prize && 0 == a.is_award_gratitude && 1 == a.is_extra_award ? this.setData({
            leveling_active: !1,
            prize_active: !1,
            extra_active: !0
        }) : 0 == a.is_flat_prize && 0 == a.is_award_gratitude && 0 == a.is_extra_award && this.setData({
            leveling_active: !1,
            prize_active: !1,
            extra_active: !1
        });
    },
    initInfo: function() {
        var a = this, t = e.getNetAddresss("plugin.team-fjyx.api.index");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 === e.result ? (e.data.is_not_agent && wx.showToast({
                    title: "你不是经销商！",
                    icon: "none"
                }), a.setData({
                    is_activation_code: e.data.is_activation_code,
                    level_name: e.data.level_name,
                    dividend_ratio: e.data.dividend_ratio,
                    next_dividend_ratio: e.data.next_dividend_ratio,
                    is_customer: e.data.is_customer,
                    is_team_data: e.data.is_team_data
                }), a.getPeople(e.data.child_count), a.getShowRed(e.data.redpack_enable), a.getTeamPerformance({
                    team_goods_total: e.data.team_goods_total,
                    team_order_price: e.data.team_order_price
                }), a.isGratitude({
                    is_award_gratitude: e.data.is_award_gratitude,
                    is_extra_award: e.data.is_extra_award,
                    is_flat_prize: e.data.is_flat_prize
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getData: function(a) {
        var t = this, i = e.getNetAddresss("plugin.team-fjyx.api.team-dividend.get-dividend-statistic");
        i += "&dividend_type=" + a, e._getNetWork({
            url: i,
            success: function(e) {
                var i = e.data;
                if (1 === i.result) {
                    var n = [], d = {};
                    d.money = i.data.today, d.data = "今日", d.name = "data", n.push(d);
                    var s = {};
                    s.money = i.data.yesterday, s.data = "昨日", s.name = "data", n.push(s);
                    var r = {};
                    r.money = i.data.this_week, r.data = "本周", r.name = "data", n.push(r);
                    var o = {};
                    o.money = i.data.this_month, o.data = "本月累计" + t.data.tab_name, o.name = "mounth", 
                    n.push(o), t.setData({
                        ratioDatas: n
                    }), 0 == a ? t.setData({
                        bonus_save: n
                    }) : 1 == a ? t.setData({
                        leveling_save: n
                    }) : 2 == a && t.setData({
                        prize_save: n
                    });
                } else wx.showToast({
                    title: i.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    openDetail: function(a) {
        console.log(a.currentTarget.dataset.ind2), console.log(this.data.display1), a.currentTarget.dataset.ind2 != this.data.display1 ? this.setData({
            display1: a.currentTarget.dataset.ind2
        }) : this.setData({
            display1: "-1"
        });
    },
    getDividendList: function(t) {
        var i = this, n = e.getNetAddresss("plugin.team-fjyx.api.team-dividend.get-dividend-list");
        n += "&dividend_type=" + t + "&page=" + this.data.page, e._getNetWork({
            url: n,
            success: function(t) {
                var e = t.data;
                if (1 === e.result) {
                    switch (i.data.dividend_type) {
                      case "0":
                        i.data.first_content.length <= 0 && i.setData(a({}, "first_content[" + i.data.first_content.length + "]", e.data.data));
                        break;

                      case "1":
                        i.data.second_content.length <= 0 && i.setData(a({}, "second_content[" + i.data.second_content.length + "]", e.data.data));
                        break;

                      case "2":
                        i.data.third_content.length <= 0 && i.setData(a({}, "third_content[" + i.data.third_content.length + "]", e.data.data));
                        break;

                      case "3":
                        i.data.four_content.length <= 0 && i.setData(a({}, "four_content[" + i.data.four_content.length + "]", e.data.data));
                    }
                    i.setData({
                        total_page: e.data.lastpage,
                        is_team_buyer: parseInt(e.data.is_team_buyer),
                        is_team_order_details: parseInt(e.data.is_team_order_details)
                    });
                } else wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    getMoreDividendList: function() {
        var t = this;
        if (this.data.page != this.data.total_page) {
            if (this.data.page >= this.data.total_page) return this.setData({
                loading: !0,
                allLoaded: !0
            }), void wx.showToast({
                title: "没有更多",
                icon: "none",
                duration: 1e3
            });
            var i = this.data.page + 1;
            this.setData({
                page: i
            });
            var n = e.getNetAddresss("plugin.team-fjyx.api.team-dividend.get-dividend-list");
            n += "&dividend_type=" + this.data.dividend_type + "&page=" + this.data.page, e._getNetWork({
                url: n,
                success: function(e) {
                    var i = e.data;
                    if (1 === i.result) {
                        switch (t.setData({
                            loading: !1,
                            allLoaded: !1
                        }), t.data.dividend_type) {
                          case "0":
                            t.setData(a({}, "first_content[" + t.data.first_content.length + "]", i.data.data));
                            break;

                          case "1":
                            t.setData(a({}, "second_content[" + t.data.second_content.length + "]", i.data.data));
                            break;

                          case "2":
                            t.setData(a({}, "third_content[" + t.data.third_content.length + "]", i.data.data));
                            break;

                          default:
                            break;

                          case "3":
                            t.setData(a({}, "four_content[" + t.data.four_content.length + "]", i.data.data));
                        }
                        t.setData({
                            total_page: i.data.lastpage
                        });
                    } else {
                        var n = t.data.page - 1;
                        t.setData({
                            page: n,
                            loading: !0,
                            allLoaded: !0,
                            isLoadMore: !1
                        });
                    }
                },
                fail: function(a) {
                    console.log(a);
                }
            });
        } else wx.showToast({
            title: "没有更多",
            icon: "none",
            duration: 1e3
        });
    },
    getDividendListByType2: function() {
        var a = this, t = e.getNetAddresss("plugin.team-fjyx.api.team-dividend.get-reward");
        e._getNetWork({
            url: t,
            success: function(t) {
                var e = t.data;
                1 === e.result ? a.setData({
                    third_content: e.data
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none"
                });
            },
            fail: function(a) {
                console.log(a);
            }
        });
    },
    setDataByTabIndex: function(a) {
        if (this.initPageData(), console.log(a, "currtitle"), "0" == i) {
            if ("额外分红" == a) {
                this.getDividendList("3");
                return this.setData({
                    dividend_type: "3",
                    tab_name: "额外分红"
                }), void this.getData("3");
            }
            this.getDividendList("0");
            var t = e.setMailLanguage("提成", this.data.mailLanguage.team_dividend.dividend);
            this.setData({
                dividend_type: "0",
                tab_name: t
            }), this.getData("0");
        } else if ("1" == i) {
            if ("额外分红" == a) {
                this.getDividendList("3");
                return this.setData({
                    dividend_type: "3",
                    tab_name: "额外分红"
                }), void this.getData("3");
            }
            if ("感恩奖" == a) {
                this.getDividendList("2");
                return this.setData({
                    dividend_type: "2",
                    tab_name: "感恩奖"
                }), void this.getData("2");
            }
            this.getDividendList("1");
            var n = e.setMailLanguage("平级奖", this.data.mailLanguage.team_dividend.flat_prize);
            this.setData({
                dividend_type: "1",
                tab_name: n
            }), this.getData("1");
        } else if ("2" == i) {
            if ("额外分红" == a) {
                this.getDividendList("3");
                return this.setData({
                    dividend_type: "3",
                    tab_name: "额外分红"
                }), void this.getData("3");
            }
            this.getDividendList("2");
            var d = e.setMailLanguage("感恩奖", this.data.mailLanguage.team_dividend.award_gratitude);
            this.setData({
                dividend_type: "2",
                tab_name: d
            }), this.getData("2");
        }
    },
    initPageData: function() {
        this.setData({
            loading: !1,
            allLoaded: !1,
            goload: !0,
            isLoadMore: !0,
            page: 1,
            total_page: 0
        });
    },
    handleClick: function(a) {
        if (console.log(a), this.setData({
            activeName: i,
            page: 1
        }), i != a.detail.index) {
            i = a.detail.index, this.setData({
                activeName: i
            }), console.log(i, "currentTabIndex");
            var t = a.detail.title;
            this.setDataByTabIndex(t);
        }
    },
    teamCode: function() {
        wx.navigateTo({
            url: "/packageE/newteamCode/newteamCode"
        });
    },
    TeamClient: function() {
        wx.navigateTo({
            url: "/packageE/newTeamClient/newTeamClient"
        });
    },
    FranchiserRed: function() {
        wx.navigateTo({
            url: "/packageE/newFranchiserRed/newFranchiserRed"
        });
    },
    teamPerformance: function() {
        wx.navigateTo({
            url: "/packageE/newteamPerformance/newteamPerformance"
        });
    }
});